﻿using StoryTeller.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoryTeller.Infrastructure.DataAccess.Parser
{
    public static class ContributionParser
    {
        public static Contribution ParseEntityToDomain(this EContribution entity)
        {
            Contribution c = new Contribution();

            c.CreationDate = entity.CreationDate;
            c.Id = entity.Id;
            c.IsPublic = entity.IsPublic;
            c.LastUpdate = entity.LastUpdate;
            c.Owner = new User() { Id = entity.OwnerId };
            c.Text = entity.Text;
            c.Chapter = new Chapter() { Id = entity.ChapterId };

            return c;
        }

        public static EContribution ParseDomainToEntity(this Contribution domain)
        {
            EContribution c = new EContribution();

            c.CreationDate = domain.CreationDate;
            c.Id = domain.Id;
            c.IsPublic = domain.IsPublic;
            c.LastUpdate = domain.LastUpdate;
            c.OwnerId = domain.Owner == null ? default(int) : domain.Owner.Id;
            c.Text = domain.Text;
            c.ChapterId = domain.Chapter.Id;

            return c;
        }
    }
}
